import pymysql
from conf import *
from loguru import logger
import traceback
from threading import Lock
import datetime

lock5=Lock()
def insert(table_name, field_name, tmp):
    for i in range(5):
        try:
            conn = pymysql.connect(**myql_params)  # 获取连接对象
            cr_obj = conn.cursor()  # 获取cursor对象
            break
        except Exception:
            continue

    try:
        st = ""
        for i in field_name:
            if i == field_name[-1]:
                st += "".join(i + ")")
            elif i == field_name[0]:
                st += "".join("(" + i + ",")
            else:
                st += "".join(i + ",")
        field_name = st

        lock5.acquire()
        # sq="insert into {}{} values(%s,%s,%s,%s)".format(table_name, field_name), tmp
        # print(sq)
        cr_obj.executemany(
            "insert into {}{} values(%s,%s,%s,%s,%s,%s,%s,%s)".format(table_name, field_name), tmp)
        conn.commit()
        last_inserted_ids = cr_obj.fetchall()
        #logger.info("sql - insert - sucesess:" + str(last_inserted_ids))
        for row in last_inserted_ids:
            return row[0]
    except Exception as e:
        traceback.print_exc()
        conn.rollback()
        #logger.info('mysql error — {}'.format(str(e).encode('utf-8')))
    finally:
        cr_obj.close()
        conn.close()
        lock5.release()
        #logger.info('close mysql')



if __name__ == '__main__':
    list=[('55', 'total_page=1; _fbc=fb.1.1706852692372.IwAR1wt1yuYT9UXOORIOdRr-dRkXLLFPnvhALd7SdlWoSPz33au2aNOz-Ot8A_aem_AcdqedCiufNB7X5TUl6ZRpUDv1lRAC92ysjwHEx-k0-Z34Nwq-5i10El3QfHiWA8NgtTerAvWqkmhbkEH9ceg9og; _fbp=fb.1.1706852692372.737254359; _gat=1; wc_prl_recently_viewed=59000|59177|55216|59217|66695|88535|58278|53864|56247|66986|82142|58741|41408|84411|83185|84326|121628|120598|88452|83122|58535,2566|2630|2603|2597|2637|2610|2668|1781|2385|2589|2611|2432|2277|2632|2604|2658|2613|2605|2673|2608|2599|2564|2585|2659|2565|2657|2606|2384|2586|2573|2598|2578|2620|2590|1770|2669|2672|2609|2592|2624|2295|2595|2601|2579,2269|1269|2675|2347|2682|2691|2239|2252|2248; _ga=GA1.1.1976079490.1706852692; _ga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mFuZHMuY29tL2Fib3V0LXVzLyIsImZpcnN0X3BhZ2UiOiJodHRwczovL2dlbnRsZWJhbmRzLmNvbS9wcm9kdWN0LWNhdGVnb3J5L3R1bmdzdGVuL3BhZ2UvMi8ifX0=; woostify_product_recently_viewed=121628%7C120598%7C83122%7C58535; _hjSession_3241374=eyJpZCI6ImZjNTg5NWZlLWJjNGUtNDA0Mi1hNGE3LTU4ZDIzNzBmMWRlYiIsImMiOjE3MDY4NTkyMDE3ODYsInMiOjAsInIiOjAsInNiIjowLCJzciI6MCwic2UiOjAsImZzIjowLCJzcCI6MH0=; total_page=1; woocommerce_cart_hash=437eabd34d2a50bfc38174be88334575; _clsk=131prk1%7C1706861163448%7C8%7C1%7Cl.clarity.ms%2Fcollect; crisp-client%2Fsession%2F4b68b1c7-9910-462f-b0f1-ea6573b28ebf=session_5b6b3db9-69ec-40a2-aa93-d79ddf9de5a4; cto_bundle=VhQfRV9iUDBBczVsOURmaEo2akJzRzZWSiUyRllMQSUyQjhoaHdJVWZ1TXdlRkV0OEdEcFRSZnhXSEIySFJhNG5zVzB0bTVDTVYlMkJUOUpVJTJCMmRRZlFZNEJQUENBT3RKMERmMzJ6JTJGVUMwdWl4WWpvRHJvalkxZmt4STJsaXNkQnhXRlI3dzY5dXE; woocommerce_items_in_cart=1; PHPSESSID=bq9u65fpld0845kk2gd55k2frg; wmc_current_currency=AUD; wmc_current_currency_old=AUD; _clck=vnsa4b%7C2%7Cfix%7C0%7C1493; wmc_ip_info=eyJjb3VudHJ5IjoiTloiLCJjdXJyZW5jeV9jb2RlIjoiTlpEIn0%3D', {'demo': [[{'id': 0, 'import_file_name': 'Fashion', 'local_import_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-1/demo-content.xml', 'local_import_widget_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-1/widgets.wie', 'local_import_customizer_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-1/customizer.dat', 'import_preview_image_url': 'https://gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-1/demo-11.jpg', 'import_notice': 'After you import this demo, you will have to setup the slider separately.', 'preview_url': 'https://demo.woostify.com/fashion1/', 'homepage': 'Fashion', 'blog_page': 'Blog', 'primary_menu': 'Header Primary', 'footer_menu': 'Footer', 'type': 'free', 'page_builder': 'elementor'}, {'id': 1, 'import_file_name': 'Yoga', 'local_import_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-2/demo-content.xml', 'local_import_widget_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-2/widgets.wie', 'local_import_customizer_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-2/customizer.dat', 'import_preview_image_url': 'https://gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-2/demo-2.jpg', 'import_notice': 'After you import this demo, you will have to setup the slider separately.', 'preview_url': 'https://demo.woostify.com/fashion2/', 'homepage': 'Woostify', 'blog_page': 'Blog', 'primary_menu': 'Primary Menu', 'footer_menu': 'Footer Menu', 'type': 'pro', 'page_builder': 'elementor'}, {'id': 2, 'import_file_name': 'Voge - Fashion', 'local_import_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-3/demo-content.xml', 'local_import_widget_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-3/widgets.wie', 'local_import_customizer_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-3/customizer.dat', 'import_preview_image_url': 'https://gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-3/demo-3.jpg', 'import_notice': 'After you import this demo, you will have to setup the slider separately.', 'preview_url': 'https://demo.woostify.com/fashion3/', 'homepage': 'Woostify', 'blog_page': 'Blog', 'primary_menu': 'Primary Menu', 'footer_menu': 'Footer Menu', 'type': 'pro', 'page_builder': 'elementor'}, {'id': 3, 'import_file_name': 'Lensvision - sunglasses', 'local_import_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-4/demo-content.xml', 'local_import_widget_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-4/widgets.wie', 'local_import_customizer_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-4/customizer.dat', 'import_preview_image_url': 'https://gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-4/demo-4.jpg', 'import_notice': 'After you import this demo, you will have to setup the slider separately.', 'preview_url': 'https://demo.woostify.com/fashion4/', 'homepage': 'Woostify', 'blog_page': 'Blog', 'primary_menu': 'Primary Menu', 'footer_menu': 'Footer Menu', 'type': 'pro', 'page_builder': 'elementor'}, {'id': 4, 'import_file_name': 'Shoebox', 'local_import_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-5/demo-content.xml', 'local_import_widget_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-5/widgets.wie', 'local_import_customizer_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-5/customizer.dat', 'import_preview_image_url': 'https://gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-5/demo-5.jpg', 'import_notice': 'After you import this demo, you will have to setup the slider separately.', 'preview_url': 'https://demo.woostify.com/', 'homepage': 'Woostify', 'blog_page': 'Blog', 'primary_menu': 'Primary Menu', 'footer_menu': 'Footer Menu', 'type': 'pro', 'page_builder': 'elementor'}, {'id': 5, 'import_file_name': 'Cosmetica - Cosmetic', 'local_import_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-6/demo-content.xml', 'local_import_widget_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-6/widgets.wie', 'local_import_customizer_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-6/customizer.dat', 'import_preview_image_url': 'https://gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-6/demo-6.png', 'import_notice': 'After you import this demo, you will have to setup the slider separately.', 'preview_url': 'https://demo.woostify.com/cosmetica/', 'homepage': 'Woostify', 'blog_page': 'Blog', 'primary_menu': 'Primary Menu', 'footer_menu': 'Footer Menu', 'type': 'pro', 'page_builder': 'elementor'}], [{'id': 6, 'import_file_name': 'Ankle - Fashion', 'local_import_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-7/demo-content.xml', 'local_import_widget_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-7/widgets.wie', 'local_import_customizer_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-7/customizer.dat', 'import_preview_image_url': 'https://gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-7/demo-7.png', 'import_notice': 'After you import this demo, you should update permalink.', 'preview_url': 'https://demo.woostify.com/ankle/', 'homepage': 'Homepage', 'blog_page': 'Blog', 'primary_menu': 'main menu', 'footer_menu': '', 'type': 'pro', 'page_builder': 'elementor'}, {'id': 7, 'import_file_name': 'Pezshop - Pet Care', 'local_import_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-8/demo-content.xml', 'local_import_widget_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-8/widgets.wie', 'local_import_customizer_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-8/customizer.dat', 'import_preview_image_url': 'https://gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-8/demo-7.png', 'import_notice': 'After you import this demo, you should update permalink.', 'preview_url': 'https://demo.woostify.com/pezshop/', 'homepage': 'Woostify', 'blog_page': 'Blog', 'primary_menu': 'Primary Menu', 'footer_menu': 'Footer Menu', 'type': 'pro', 'page_builder': 'elementor'}, {'id': 8, 'import_file_name': 'Watch - Watch Shop', 'local_import_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-9/demo-content.xml', 'local_import_widget_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-9/widgets.wie', 'local_import_customizer_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-9/customizer.dat', 'import_preview_image_url': 'https://gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-9/demo-9.png', 'import_notice': 'After you import this demo, you should update permalink.', 'preview_url': 'https://demo.woostify.com/watch/', 'homepage': 'Homepage', 'blog_page': 'Blog', 'primary_menu': 'Main Menu', 'footer_menu': '', 'type': 'pro', 'page_builder': 'elementor'}, {'id': 9, 'import_file_name': 'Hippine - Jewelry ', 'local_import_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-10/demo-content.xml', 'local_import_widget_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-10/widgets.wie', 'local_import_customizer_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-10/customizer.dat', 'import_preview_image_url': 'https://gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-10/demo-10.png', 'import_notice': 'After you import this demo, you should update permalink.', 'preview_url': 'https://demo.woostify.com/hippine/', 'homepage': 'Homepage', 'blog_page': 'Blog', 'primary_menu': 'main menu', 'footer_menu': '', 'type': 'pro', 'page_builder': 'elementor'}, {'id': 10, 'import_file_name': 'Furnito - Furniture', 'local_import_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-11/demo-content.xml', 'local_import_widget_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-11/widgets.wie', 'local_import_customizer_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-11/customizer.dat', 'import_preview_image_url': 'https://gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-11/demo-11.png', 'import_notice': 'After you import this demo, you should update permalink.', 'preview_url': 'https://demo.woostify.com/furnito/', 'homepage': 'Woostify', 'blog_page': 'Blog', 'primary_menu': 'Primary Menu', 'footer_menu': 'Footer Menu', 'type': 'pro', 'page_builder': 'elementor'}, {'id': 11, 'import_file_name': 'Pizza', 'local_import_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-12/demo-content.xml', 'local_import_widget_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-12/widgets.wie', 'local_import_customizer_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-12/customizer.dat', 'import_preview_image_url': 'https://gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-12/demo-12.png', 'import_notice': 'After you import this demo, you should update permalink.', 'preview_url': 'https://demo.woostify.com/pizza/', 'homepage': 'Woostify', 'blog_page': 'Blog', 'primary_menu': 'Primary Menu', 'footer_menu': 'Footer Menu', 'type': 'pro', 'page_builder': 'elementor'}], [{'id': 12, 'import_file_name': 'Urbanstyle', 'local_import_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-13/demo-content.xml', 'local_import_widget_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-13/widgets.wie', 'local_import_customizer_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-13/customizer.dat', 'import_preview_image_url': 'https://gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-13/demo-13.png', 'import_notice': 'After you import this demo, you should update permalink.', 'preview_url': 'https://demo.woostify.com/urbanstyle', 'homepage': 'Fashion', 'blog_page': 'Blog', 'primary_menu': 'Header Primary', 'footer_menu': 'Footer', 'type': 'free', 'page_builder': 'elementor'}, {'id': 13, 'import_file_name': 'Randy', 'local_import_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-14/demo-content.xml', 'local_import_widget_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-14/widgets.wie', 'local_import_customizer_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-14/customizer.dat', 'import_preview_image_url': 'https://gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-14/demo-14.png', 'import_notice': 'After you import this demo, you should update permalink.', 'preview_url': 'https://demo.woostify.com/randy/', 'homepage': 'Woostify', 'blog_page': 'Blog', 'primary_menu': 'Primary Menu', 'footer_menu': 'Footer Menu', 'type': 'pro', 'page_builder': 'elementor'}, {'id': 14, 'import_file_name': 'Mega Shop', 'local_import_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-15/demo-content.xml', 'local_import_widget_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-15/widgets.wie', 'local_import_customizer_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-15/customizer.dat', 'import_preview_image_url': 'https://gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-15/demo-15.png', 'import_notice': 'After you import this demo, you should update permalink.', 'preview_url': 'https://demo.woostify.com/megashop/', 'homepage': 'Woostify', 'blog_page': 'Blog', 'primary_menu': 'Primary Menu', 'vertical_menu': 'Menu Vertical', 'footer_menu': 'Footer Menu', 'type': 'pro', 'page_builder': 'elementor'}, {'id': 15, 'import_file_name': 'Auto Car', 'local_import_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-16/demo-content.xml', 'local_import_widget_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-16/widgets.wie', 'local_import_customizer_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-16/customizer.dat', 'import_preview_image_url': 'https://gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-16/demo-16.png', 'import_notice': 'After you import this demo, you should update permalink.', 'preview_url': 'https://demo.woostify.com/autocar/', 'homepage': 'Home', 'blog_page': 'Blog', 'primary_menu': 'Primary Menu', 'vertical_menu': 'Menu Vertical', 'type': 'pro', 'page_builder': 'elementor'}, {'id': 16, 'import_file_name': 'Meins', 'local_import_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-17/demo-content.xml', 'local_import_widget_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-17/widgets.wie', 'local_import_customizer_file': '/www/wwwroot/gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-17/customizer.dat', 'import_preview_image_url': 'https://gentlebands.com/wp-content/plugins/woostify-sites-library/demos/demo-17/demo-17.png', 'import_notice': 'After you import this demo, you should update permalink.', 'preview_url': 'https://demo.woostify.com/meins/', 'homepage': 'Home', 'blog_page': 'Blog', 'primary_menu': 'Primary Menu', 'type': 'pro', 'page_builder': 'elementor'}]]}, '2024-02-02 08:08:37')]
    field_name = ('content_str', 'cookie_str', 'session_str', 'create_time')
    bb=[]
    for x in list:
        bb.append(str(x))
    insert('t_dlz_access_records', field_name, bb)